package cn.gson.springboot.model.service;

import cn.gson.springboot.model.dao.OpportunityDao;
import cn.gson.springboot.model.mapper.OpportunityMapper;
import cn.gson.springboot.model.pojos.Opportunity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class OpportunityService {
    @Autowired
    OpportunityMapper oppMapper;
    @Autowired
    OpportunityDao oppDao;
    @Autowired
    CustomerService customerService;

    public List<Opportunity> selectEmpOpportunity(Integer deptId,Integer empId,Integer value,Integer num,Integer vague,String content){
        return oppMapper.selectEmpOpportunity(deptId,empId,value,num,vague,content);
    }

    public List<Opportunity> selectCusOpportunity(Integer cusId){
        return oppMapper.selectCusOpportunity(cusId);
    }

    public List<Map<String,Object>> computeOppByEmp(Integer deptId,Integer empId){
        return oppMapper.computeOppByEmp(deptId,empId);
    }

    public List<Map<String,Object>> computeSource(Integer deptId,Integer empId){
        return oppMapper.computeSource(deptId,empId);
    }

    public List<Map<String,Object>> computeClassify(Integer deptId,Integer empId){
        return oppMapper.computeClassify(deptId,empId);
    }

    public List<Map<String,Object>> computeFindDate(Integer deptId,Integer empId){
        return oppMapper.computeFindDate(deptId,empId);
    }

    public List<Map<String,Object>> computeSignDate(Integer deptId,Integer empId){
        return oppMapper.computeSignDate(deptId,empId);
    }

    public List<Map<String,Object>> computeStatus(Integer deptId,Integer empId){
        return oppMapper.computeStatus(deptId,empId);
    }

    public List<Map<String,Object>> computeStage(Integer deptId,Integer empId){
        return oppMapper.computeStage(deptId,empId);
    }

    public List<Map<String,Object>> computeStageOther(Integer deptId,Integer empId){
        return oppMapper.computeStageOther(deptId,empId);
    }

    public List<Map<String,Object>> computeStageMin(Integer empId){
        return oppMapper.computeStageMin(empId);
    }

    public List<Map<String,Object>> computeStageMedium(Integer empId){
        return oppMapper.computeStageMedium(empId);
    }

    public List<Map<String,Object>> computeStageMax(){
        return oppMapper.computeStageMax();
    }

    public List<Map<String,Object>> computePossibility(Integer deptId,Integer empId){
        return oppMapper.computePossibility(deptId,empId);
    }

    @Transactional(transactionManager = "transactionManager")
    public Opportunity saveOpportunity(Opportunity opportunity){
        oppDao.save(opportunity);
        return opportunity;
    }

    @Transactional(transactionManager = "transactionManager")
    public void deleteOpportunity(Integer oppId){
      oppDao.deleteById(oppId);
    }
}
